//销退入库单
import React, { useState, useEffect, useRef } from 'react';
import SearchContent from './component/SearchContent';
import TableContent from './component/TableContent';
import { useLocation } from 'react-router-dom';

const RetireWarehouse = () => {
  const [query, setQuery] = useState(null);
  //设置查询的key
  const [tableKey, setTableKey] = useState(0);
  const divEl = useRef(null);

  const location = useLocation();

  //处理页面跳转
  useEffect(() => {
    if (location.pathname == '/stock/warehousingOrder/RetireWarehouse') {
      if (location.state?.orderSn) {
        setQuery({
          returnOrderSn: location.state.orderSn,
        });
        window.history.replaceState('', '');
      }
    }
    setTableKey(tableKey + 1);
  }, [location.pathname]);

  const searchProps = {
    query,
    handleSearch(val) {
      if (val && Object.keys(val)?.length) {
        setQuery(val);
      } else {
        setQuery({});
      }
      setTableKey(tableKey + 1);
    },
  };

  const tableProps = {
    query,
    divEl,
    tableKey,
  };

  return (
    <div className="zjf-container">
      <div ref={divEl}>
        <SearchContent {...searchProps} />
      </div>
      <TableContent {...tableProps} />
    </div>
  );
};

export default React.memo(RetireWarehouse, () => {
  return true;
});
